// https://leetcode.cn/problems/minimum-size-subarray-sum/description/?envType=study-plan-v2&envId=top-interview-150

class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int n = nums.size();
        int ans = 10e6;

        int left = 0, sum = 0, count = 0;
        while (left < n || sum >= target) {
            if (sum < target) {
                sum += nums[left];
                left++;
                count++;
            } else {
                ans = min(ans, count);
                sum -= nums[left - count];
                count--;
            }
        }
        return ans == 10e6? 0: ans;
    }
};